import { BasicColumn, FormSchema } from '@/components/Table';
import { dateUtil } from '@/utils/dateUtil';

export const carColumns: BasicColumn[] = [
  {
    title: '优惠券类型',
    dataIndex: 'name',
    width: 50,
  },
  {
    title: '金额',
    dataIndex: 'amount',
    width: 50,
  },
  {
    title: '创建时间',
    dataIndex: 'createDate',
    width: 160,
    customRender: ({ text }) => {
      return dateUtil(text).format('YYYY-MM-DD HH:mm:ss');
    },
  },
  {
    title: '生效时间',
    dataIndex: 'startDate',
    width: 160,
    customRender: ({ text }) => {
      return dateUtil(text).format('YYYY-MM-DD HH:mm:ss');
    },
  },
  {
    title: '失效时间',
    dataIndex: 'endDate',
    width: 160,
    customRender: ({ text }) => {
      return text == null ? '' : dateUtil(text).format('YYYY-MM-DD HH:mm:ss');
    },
  },
  {
    title: '所属人',
    dataIndex: 'mname',
    width: 50,
  },
  {
    title: '手机号',
    dataIndex: 'mphone',
    width: 50,
  },
  {
    title: '使用时间',
    dataIndex: 'useDate',
    width: 160,
    customRender: ({ text }) => {
      return text == null ? '' : dateUtil(text).format('YYYY-MM-DD HH:mm:ss');
    },
  },
  {
    title: '满多少可以使用',
    dataIndex: 'byFull',
    width: 50,
  },
  {
    title: '表达式',
    dataIndex: 'expression',
    width: 50,
  },
  {
    title: '备注',
    dataIndex: 'memo',
    width: 50,
  },
  {
    title: '状态',
    dataIndex: 'status',
    width: 50,
    customRender: ({ text }) => {
      if (text == '0') {
        return '未使用';
      } else if (text == '1') {
        return '已使用';
      } else if (text == '2') {
        return '已过期';
      }
    },
  },
];
export const adminColumns: BasicColumn[] = [
  {
    title: '优惠券名称',
    dataIndex: 'name',
    width: 50,
  },
  {
    title: '金额',
    dataIndex: 'amount',
    width: 50,
  },
  {
    title: '生效时间',
    dataIndex: 'startDate',
    width: 160,
    customRender: ({ text }) => {
      return dateUtil(text).format('YYYY-MM-DD HH:mm:ss');
    },
  },
  {
    title: '失效时间',
    dataIndex: 'endDate',
    width: 160,
    customRender: ({ text }) => {
      return dateUtil(text).format('YYYY-MM-DD HH:mm:ss');
    },
  },
  {
    title: '有效时段',
    dataIndex: 'times',
    width: 50,
    customRender: ({ text }) => {
      if (text == '0') {
        return '否';
      } else if (text == '1') {
        return '是';
      }
    },
  },
  {
    title: '满多少可以用',
    dataIndex: 'byFull',
    width: 50,
  },
  {
    title: '表达式',
    dataIndex: 'expression',
    width: 50,
  },
  {
    title: '备注',
    dataIndex: 'memo',
    width: 50,
  },
];
export const adminSearchFormSchema: FormSchema[] = [
  {
    field: 'startTime',
    label: '开始时间',
    component: 'DatePicker',
    componentProps: {
      format: 'YYYY-MM-DD',
      valueFormat: 'YYYY-MM-DD',
      style: { width: '100%' },
    },
    colProps: {
      span: 5,
    },
  },
  {
    field: 'endTime',
    label: '结束时间',
    component: 'DatePicker',
    componentProps: {
      format: 'YYYY-MM-DD',
      valueFormat: 'YYYY-MM-DD',
      style: { width: '100%' },
    },
    colProps: {
      span: 5,
    },
  },
  {
    field: 'keyword',
    label: '优惠券类型名称',
    component: 'Input',
    colProps: {
      span: 5,
    },
  },
];
export const carSearchFormSchema: FormSchema[] = [
  {
    field: 'status',
    label: '状态',
    component: 'Select',
    labelWidth: 90,
    componentProps: {
      options: [
        { name: '未使用', id: '0' },
        { name: '已使用', id: '1' },
        { name: '已过期', id: '2' },
      ],
      fieldNames: {
        label: 'name',
        key: 'id',
        value: 'id',
      },
    },
    colProps: {
      span: 6,
    },
  },
  {
    field: 'startDate',
    label: '开始时间',
    component: 'DatePicker',
    componentProps: {
      format: 'YYYY-MM-DD',
      valueFormat: 'YYYY-MM-DD',
      style: { width: '100%' },
    },
    colProps: {
      span: 5,
    },
  },
  {
    field: 'endDate',
    label: '结束时间',
    component: 'DatePicker',
    componentProps: {
      format: 'YYYY-MM-DD',
      valueFormat: 'YYYY-MM-DD',
      style: { width: '100%' },
    },
    colProps: {
      span: 5,
    },
  },
  {
    field: 'keyword',
    label: '优惠券类型名称',
    component: 'Input',
    colProps: {
      span: 5,
    },
  },
];
export const adminFormSchema: FormSchema[] = [
  {
    field: 'id',
    label: '主键',
    component: 'Input',
    show: false,
  },
  {
    field: 'name',
    label: '优惠券名称',
    component: 'Input',
  },
  {
    field: 'amount',
    label: '优惠券金额',
    component: 'InputNumber',
    componentProps: {
      precision: 2,
      min: 0,
      max: 100000000,
    },
    required: true,
  },
  {
    field: 'startDate',
    label: '开始时间',
    component: 'DatePicker',
    componentProps: {
      format: 'YYYY-MM-DD',
      // valueFormat: 'YYYY-MM-DD',
      style: { width: '100%' },
    },
    required: true,
  },
  {
    field: 'endDate',
    label: '结束时间',
    component: 'DatePicker',
    componentProps: {
      format: 'YYYY-MM-DD',
      // valueFormat: 'YYYY-MM-DD',
      style: { width: '100%' },
    },
    required: true,
  },
  {
    field: 'byFull',
    label: '满多少可以使用优惠',
    component: 'InputNumber',
    componentProps: {
      precision: 2,
      min: 0,
      max: 100000000,
    },
    required: true,
  },
  {
    field: 'expression',
    label: '优惠券表达式',
    helpMessage: 'price代表订单金额,service代表服务费,例如price*0.8-service',
    component: 'Input',
  },
  {
    field: 'stationIdArray',
    label: '可使用场站',
    component: 'ApiCheckboxGroup',
    componentProps: {
      api: '/admin/station/listAll',
      labelField: 'name',
      valueField: 'id',
    },
    colProps: {
      span: 24,
    },
  },
];
